package com.tencreat.service.mall.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tencreat.common.core.HttpResult;
import com.tencreat.common.core.domain.model.AccountLogin;
import com.tencreat.common.core.domain.model.ReqIdParam;
import com.tencreat.common.core.domain.model.ReqIdsParam;
import com.tencreat.domain.mall.BalanceChange;
import com.tencreat.domain.mall.GoodsRollOrder;
import com.tencreat.domain.mall.vo.AccumulatedVO;
import com.tencreat.mapper.mall.BalanceChangeMapper;
import com.tencreat.service.mall.IBalanceChangeService;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;

/**
 * 余额变动Service业务层处理
 *
 * @author wangkai
 * @date 2021-11-15
 */
@Service
public class BalanceChangeServiceImpl extends ServiceImpl<BalanceChangeMapper, BalanceChange> implements IBalanceChangeService {


    /**
     * 查询余额变动
     *
     * @param id 余额变动ID
     * @return 余额变动
     */
    @Override
    public BalanceChange selectBalanceChangeById(ReqIdParam id) {
        return baseMapper.selectById(id.getId());
    }

    /**
     * 查询余额变动列表
     *
     * @param balanceChange 余额变动
     * @return 余额变动
     */
    @Override
    public List<BalanceChange> selectBalanceChangeList(BalanceChange balanceChange) {
        return baseMapper.selectList(Wrappers.query(balanceChange));
    }

    /**
     * 新增余额变动
     *
     * @param balanceChange 余额变动
     * @return 结果
     */
    @Override
    public int insertBalanceChange(BalanceChange balanceChange) {
    balanceChange.setCreateTime(LocalDateTime.now());
        return baseMapper.insert(balanceChange);
    }

    /**
     * 修改余额变动
     *
     * @param balanceChange 余额变动
     * @return 结果
     */
    @Override
    public int updateBalanceChange(BalanceChange balanceChange) {
        balanceChange.setUpdateTime(LocalDateTime.now());
        return baseMapper.updateById(balanceChange);
    }

    /**
     * 批量删除余额变动
     *
     * @param ids 需要删除的余额变动ID
     * @return 结果
     */
    @Override
    public int deleteBalanceChangeByIds(ReqIdsParam ids) {
        return baseMapper.deleteBatchIds(ids.getId());
    }

    /**
     * 删除余额变动信息
     *
     * @param id 余额变动ID
     * @return 结果
     */
    @Override
    public int deleteBalanceChangeById(ReqIdParam id) {
        return baseMapper.deleteById(id.getId());
    }

    @Override
    public BigDecimal sumByReferrer(Long uuid) {
        return baseMapper.sumByReferrer(uuid);
    }


    @Override
    public AccumulatedVO accumulatedRecharge(AccountLogin accountLogin) {
        return baseMapper.accumulatedRecharge(accountLogin.getUuid());
    }

    @Override
    public AccumulatedVO accumulatedConsumer(AccountLogin accountLogin) {
        return baseMapper.accumulatedConsumer(accountLogin.getUuid());
    }

    @Override
    public IPage<GoodsRollOrder> goodsRollList(Page<GoodsRollOrder> page, GoodsRollOrder goodsRollOrder) {

        return baseMapper.goodsRollList(page,goodsRollOrder);
    }

    @Override
    public BigDecimal rechargeAmount() {
        return baseMapper.rechargeAmount();
    }

    @Override
    public BigDecimal useTotalConsumeRoll() {
        return baseMapper.useTotalConsumeRoll();
    }
}
